
package uk.ac.cam.cl.oscar.MMS_server;

import java.net.Socket;
import java.net.ServerSocket;
import java.io.IOException;
import uk.ac.cam.cl.oscar.Demonstration;


public class MainServer implements Runnable{
    private static Demonstration DemoAppInst=null;
    
    public static void main(String[] args) {
        
        try{
            System.setProperty("com.sun.media.jai.disableMediaLib", "true");
            System.out.printf("Server Started.......%n");
            
            /*listen on port for incoming connections*/
            ServerSocket ss = new ServerSocket(5000);
            
            /*infinite loop to always accept connections*/
            while(true){
                Socket s = ss.accept(); //accept incoming connection
                System.out.printf("%nNew Connection received.......%n");
                RequestProcessor rp = new RequestProcessor(s); //instantiate RequestProcessor class
                (new Thread(rp)).start(); //start new thread for processing request
            }
        }
        catch(IOException e){
            System.out.printf("IOException occurred in MainServer");
        }
        
    }

    public void run() {
        
        main(null);
    }
    
    

}
